<?php
/**
 * Desc:
 * User: yangyang
 * Date: 2024/4/8 15:33
 * Ver: 1.0
 */

namespace App\Transformers;

use App\Models\OrderDetails;
use League\Fractal\TransformerAbstract;

class OrderDetailTransformer extends TransformerAbstract
{
    protected $availableIncludes = ['goods', 'order'];

    public function transform(OrderDetails $orderDetails)
    {
        return [
            'id'         => $orderDetails->id,
            'order_id'   => $orderDetails->order_id,
            'goods_id'    => $orderDetails->goods_id,
            'price'      => $orderDetails->price,
            'num'        => $orderDetails->num,
            'created_at' => $orderDetails->created_at->toDateTimeString(),
            'updated_at' => $orderDetails->updated_at->toDateTimeString(),
        ];
    }
    public function includeOrder(OrderDetails $orderDetails)
    {
        return $this->item($orderDetails->order, new OrderTransformer());
    }

    public function includeGoods(OrderDetails $orderDetails)
    {
        return $this->item($orderDetails->goods, new GoodTransformer());
    }
}
